package com.banshuibao.bsb_android.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.banshuibao.bsb_android.R;
import com.banshuibao.bsb_android.model.KnowledgeModel;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wangpan on 2018/5/19.
 */

public class MoreDataQueryListAdapter extends BaseAdapter {

    private Context context;
    private List<KnowledgeModel.DataBean> list;
    private final LayoutInflater inflater;

    public MoreDataQueryListAdapter(Context context) {
        this.context = context;
        inflater = LayoutInflater.from(context);
        list = new ArrayList<>();
    }

    //税收案例
    public void setTaxUp(List<KnowledgeModel.DataBean> list) {
        if (this.list != null && this.list.size() > 0) {
            this.list.addAll(list);
        }
        notifyDataSetChanged();
    }

    //法院判例
    public void setJudicialUp(List<KnowledgeModel.DataBean> list) {
        if (this.list != null && this.list.size() > 0) {
            this.list.addAll(list);
        }
        notifyDataSetChanged();
    }

    //稽查案例
    public void setAuditingUp(List<KnowledgeModel.DataBean> list) {
        if (this.list != null && this.list.size() > 0) {
            this.list.addAll(list);
        }
        notifyDataSetChanged();
    }

    //名师导航
    public void setNavigationUp(List<KnowledgeModel.DataBean> list) {
        if (this.list != null) {
            this.list.addAll(list);
        }
        notifyDataSetChanged();
    }

    //绝对收藏
    public void setCollectionUp(List<KnowledgeModel.DataBean> list) {
        if (this.list != null) {
            this.list.addAll(list);
        }
        notifyDataSetChanged();
    }

    //税收案例
    public void setTaxDown(List<KnowledgeModel.DataBean> list) {
        if (this.list != null) {
            this.list.clear();
            this.list.addAll(list);
        }
        notifyDataSetChanged();
    }

    //法院判例
    public void setJudicialDown(List<KnowledgeModel.DataBean> list) {
        if (this.list != null) {
            this.list.clear();
            this.list.addAll(list);
        }
        notifyDataSetChanged();
    }

    //稽查案例
    public void setAuditingDown(List<KnowledgeModel.DataBean> list) {
        if (this.list != null) {
            this.list.clear();
            this.list.addAll(list);
        }
        notifyDataSetChanged();
    }

    //名师导航
    public void setNavigationDown(List<KnowledgeModel.DataBean> list) {
        if (this.list != null) {
            this.list.clear();
            this.list.addAll(list);
        }
        notifyDataSetChanged();
    }

    //绝对收藏
    public void setCollectionDown(List<KnowledgeModel.DataBean> list) {
        if (this.list != null) {
            this.list.clear();
            this.list.addAll(list);
        }
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list != null ? list.size() : 0;
    }

    @Override
    public KnowledgeModel.DataBean getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.search_content_layout, null);
            viewHolder = new ViewHolder();
            viewHolder.tv = convertView.findViewById(R.id.content);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tv.setText(list.get(position).getTitle());
        return convertView;
    }

    public class ViewHolder {
        TextView tv;
    }

    public void clearAdapter() {
        if (list != null) {
            list.clear();
            notifyDataSetChanged();
        }
    }


}
